<template>
	<view class="login-con">
		<view class="cus-title">
			<view class="top-img">
				<view>
					<image style="width:80px; height: 63px;" mode="aspectFit" src="../../static/img/logo.png"></image>
				</view>
				<view class="v-m ym">益民</view>
				<view class="v-m">菜市</view>
			</view>
		</view>
		<view class="login">
			<uni-forms ref="baseForm" :modelValue="sysLoginRequest">
				<uni-forms-item required>
					<uni-easyinput v-model="sysLoginRequest.accName" placeholder="请输入账号" />
				</uni-forms-item>
				<uni-forms-item required>
					<uni-easyinput type="password" v-model="sysLoginRequest.passWord" placeholder="请输入密码" />
				</uni-forms-item>

			</uni-forms>
			<button  class="login-btn" :disabled="!sysLoginRequest.accName||!sysLoginRequest.passWord"
				@click="submit()">登录</button>
				<!--type="primary"-->
		</view>

	</view>
</template>

<script setup lang="ts">
	import {ref} from 'vue';
	import {hex_md5} from '/@/utils/md5';
	import {BaseAPI} from '/@/api/BaseAPI'
	import SysLoginRequest from '/@/entity/base/request/SysLoginRequest';
	import { MessagePopup } from '/@/utils/MessagePopup';

	const sysLoginRequest = ref<SysLoginRequest>(new SysLoginRequest());
	uni.getStorage({
		key: 'token',
		success: function(res) {
			console.log(res);
			console.log("存在登录信息~")
			// uni.switchTab({
			// 	url: '/pages/index/index'
			// })
		}
	});
	//取出权限值
	// function takeOutPermission(arr=[]){
	// 	console.log(arr)
	// 	arr.forEach(item=>{
	// 		if(item.children!==null){
	// 			takeOutPermission(item.children)
	// 		}else{
	// 			if(item.buttonResource!=null){
	// 				allButtonResource.value = allButtonResource.value.concat(item.buttonResource)
	// 			}
	// 			return 
	// 		}
	// 	})
	// }
	const submit = () => {
		sysLoginRequest.value.loginMode='1'

		sysLoginRequest.value.passWord=hex_md5(sysLoginRequest.value.passWord)
		BaseAPI.login(sysLoginRequest.value).then((res)=>{
			if (res.code === 0) {
				MessagePopup.msg('登录成功')	
				uni.setStorage({
					key: 'userInfo',
					data: res.data,
				});
				uni.setStorage({
					key: 'token',
					data:res.data.jwtTokenInfo.accessToken,
					success:()=>{
						uni.switchTab({
							url: '/pages/index/index'
						})
					}
				})
			}else{
				MessagePopup.error(res.message || '用户信息有误')	
			}
		})


		// login(baseFormData.value).then((res: any) => {
		// 	if (res.code === 0) {
		// 		uni.showToast({
		// 			icon: 'none',
		// 			title: '登录成功',
		// 			duration:500
		// 		});
		// 		// uni.setStorage({
		// 		// 	key: 'userInfo',
		// 		// 	data: baseFormData.value,
		// 		// });
		// 		uni.setStorage({
		// 			key: 'userInfo',
		// 			data: res.data.userInfoResponse,
		// 		});
		// 		takeOutPermission(res.data.userResourceResponseList||[])
		// 		// console.log('所有权限----------',allButtonResource.value);
				
		// 		uni.setStorageSync(
		// 			'MenuList',
		// 			allButtonResource.value
		// 		);
		// 		uni.setStorage({
		// 			key: 'tokenInformation',
		// 			data: res.data.tokenInformation,
		// 			success: () => {
		// 				uni.switchTab({
		// 					url: '/pages/index/index'
		// 				})
		// 			}
		// 		});

		// 	}
		// })
	}
</script>

<style scoped lang="scss">
	.login-con {
		height: 100vh;
		background-color: #fff;
		display: flex;
		flex-direction: column;
	}

	.cus-title {
		width: 100%;
		height: 500rpx;
		background: url('../../static/img/bg.png') no-repeat;
		background-size: 100% 100%;
		background-position: top;
		text-align: center;
		color: #fff;
		letter-spacing: 3px;
		font-size: 20px;
		padding-top: 140rpx;
		box-sizing: border-box;

		.top-img {
			.ym {
				font-size: 24px;
				font-weight: bold;
			}
		}
	}

	.login {
		width: 100%;
		// height: 300px;
		box-sizing: border-box;
		margin-top: -30px;
		background-color: #fff;
		border-top-right-radius: 30px;
		padding-top: 50px;
		padding: 50px 40px;
		flex: 1;

		.login-btn {
			// width: 100%;
			line-height: 40px;
			background: #2AA37D;
			border: 1px solid #EEEEEE;
			border-radius: 34px;

		}
	}

	:deep(.is-input-border) {
		border-radius: 30px;
	}
</style>
